package com.yanqu.road.server.cmd.activity.hsisland;

import com.yanqu.road.entity.activity.hsisland.data.HsIslandEventData;
import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.HsIslandProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.hsisland.CrossHsIslandActivity;
import com.yanqu.road.server.manager.activity.hsisland.CrossHsIslandActivityMgr;
import com.yanqu.road.server.manager.activity.hsisland.CrossHsIslandUser;
import com.yanqu.road.server.manager.activity.hsisland.pb.CrossHsIslandActivityPb;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

import java.util.List;

@Cmd(code = Protocol.C2_HS_ISLAND_USE_IMAGE, desc = "海神岛-穿戴形象")
public class CrossHsIslandUseImageCmd extends CrossUnionCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        HsIslandProto.HsIslandUseImageReqMsg reqMsg = HsIslandProto.HsIslandUseImageReqMsg.parseFrom(packet.getBytes());
        HsIslandProto.HsIslandUseImageRespMsg.Builder respMsg = HsIslandProto.HsIslandUseImageRespMsg.newBuilder();
        CrossHsIslandActivity activity = CrossHsIslandActivityMgr.getActivity(reqMsg.getActivityId(), groupId);
        if (activity == null) {
            respMsg.setRet(GameErrorCode.E_HS_ISLAND_ACTIVITY_NOT_FOUND);
            MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_HS_ISLAND_USE_IMAGE, respMsg));
            return;
        }
        try {
            //穿戴形象
            activity.useImage(packet.getPlayerId(), reqMsg.getImageId());
            //构造PB
            CrossHsIslandUser user = activity.getUser(packet.getPlayerId());
            respMsg.setRet(0);
            respMsg.setUserData(CrossHsIslandActivityPb.buildHsIslandUserData(user));
        } catch (BusinessException e) {
            respMsg.setRet(e.getCode());
        }
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_HS_ISLAND_USE_IMAGE, respMsg));
    }

    @Override
    public void sendData() {}
}
